package com.betterjr.modules.loan.dao;

import java.math.BigDecimal;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;

import com.betterjr.common.annotation.BetterjrMapper;
import com.betterjr.mapper.common.Mapper;
import com.betterjr.modules.loan.entity.ScfPayRecord;

@BetterjrMapper
public interface ScfPayRecordMapper extends Mapper<ScfPayRecord> {

    /*
     * 查询出资金方过去每月放款的金额
     */
    @Select("select sum(F_LOAN_BALANCE)/10000 as monthTotalBalance from t_scf_request where L_FACTORNO=#{factorNo} and C_LAST_STATUS in('4','5','6','7') and D_ACTUAL_DATE between #{startDate} and #{endDate}")
    @ResultType(BigDecimal.class)
    BigDecimal statisticEveryMonthLoadBalance(@Param("factorNo") String requestNo, @Param("startDate") String startDate,
            @Param("endDate") String endDate);

    /*
     * 查询出资金方过去每月回款的金额
     */
    @Select("select sum(F_LOAN_BALANCE)/10000 as monthTotalBalance from t_scf_request where L_FACTORNO=#{factorNo} and C_LAST_STATUS='8' and D_CLEAN_DATE between #{startDate} and #{endDate}")
    @ResultType(BigDecimal.class)
    BigDecimal statisticEveryMonthPayBalance(@Param("factorNo") String factorNo, @Param("startDate") String startDate,
            @Param("endDate") String endDate);

    /*
     * 查询出核心企业过去每月应付款的金额
     */
    @Select("select sum(F_LOAN_BALANCE)/10000 as monthTotalBalance from t_scf_request where L_CORE_CUSTNO=#{coreCustNo} and "
            + "C_LAST_STATUS in('4','5','6','7') and D_END_DATE between #{startDate} and #{endDate}")
    @ResultType(BigDecimal.class)
    BigDecimal statisticcoreEnterpriseEveryMonthLoadBalance(@Param("coreCustNo") String coreCustNo,
            @Param("startDate") String startDate, @Param("endDate") String endDate);

    /*
     * 查询出核心企业过去没有已付款的金额
     */
    @Select("select sum(F_LOAN_BALANCE)/10000 as monthTotalBalance from t_scf_request where L_CORE_CUSTNO=#{coreCustNo} and C_LAST_STATUS='8' and D_CLEAN_DATE between #{startDate} and #{endDate}")
    @ResultType(BigDecimal.class)
    BigDecimal statisticCoreEnterPriseEveryMonthPayBalance(@Param("coreCustNo") String coreCustNo,
            @Param("startDate") String startDate, @Param("endDate") String endDate);

    /*
     * 统计出资金方全部利息
     */
    @Select("select sum(F_PAY_BALANCE)/10000 as interestTotalBalance from t_scf_pay_record_detail where L_FACTORNO=#{factorNo} and C_PAY_TYPE='2'")
    @ResultType(BigDecimal.class)
    BigDecimal statisticTotalInterestPayBalance(@Param("factorNo") String factorNo);

    /*
     * 统计出资金方全部手术费
     */
    @Select("select sum(F_PAY_BALANCE)/10000 as interestTotalBalance from t_scf_pay_record_detail where L_FACTORNO=#{factorNo} and C_PAY_TYPE in('7','8')")
    @ResultType(BigDecimal.class)
    BigDecimal statisticTotalOperationPayBalance(@Param("factorNo") String factorNo);

    /*
     * 统计出资金方所有管理费
     */
    @Select("select sum(F_PAY_BALANCE)/10000 as ManagerTotalBalance from t_scf_pay_record_detail where L_FACTORNO=#{factorNo} and C_PAY_TYPE='3'")
    @ResultType(BigDecimal.class)
    BigDecimal statisticTotalManagerPayBalance(@Param("factorNo") String factorNo);

    /*
     * 统计出资金方所有其他费用
     */
    @Select("select sum(F_PAY_BALANCE)/10000 as OtherTotalBalance from t_scf_pay_record_detail where L_FACTORNO=#{factorNo} and C_PAY_TYPE='6'")
    @ResultType(BigDecimal.class)
    BigDecimal statisticTotalOtherPayBalance(@Param("factorNo") String factorNo);

}